如何通过Postgres SQL插入数据库

时间:2019-01-08 06:24:52

标签: javascript node.js postgresql

我有以下代码将值插入数据库

db.one('INSERT INTO transactions (transaction_id) VALUES (a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a11)')
    .then(user => {
        console.log(user.name); // print user name;
    })
    .catch(error => {
        console.log(error, 'jjjjjjjjjjjj'); // print the error;
    });

我想插入三个字段

1) transaction_id 
2) amount 
3) currencies_currency_id

但是出错了

error: syntax error at or near "c0b"

请在这里帮助我做错了

1 个答案:

答案 0 :(得分:3)

我认为SQL值需要单引号

尝试

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Unite Gallery - Tiles - Nested</title>

	<script type='text/javascript' src='unitegallery/js/jquery-11.0.min.js'></script>	
	<script type='text/javascript' src='unitegallery/js/unitegallery.min.js'></script>	

	<link rel='stylesheet' href='unitegallery/css/unite-gallery.css' type='text/css' />
	
	<script type='text/javascript' src='unitegallery/themes/tiles/ug-theme-tiles.js'></script>
	
	
</head>

<body>
	
	<h2>Tiles - Nested</h2>
	
	<div id="gallery" style="display:none;">

		<a href="http://unitegallery.net">
		<img alt="Lemon Slice"
		     src="images/thumbs/tile1.jpg"
		     data-image="images/big/tile1.jpg"
		     data-description="This is a Lemon Slice"
		     style="display:none">
		</a>

		<a href="http://unitegallery.net">
		<img alt="Peppers"
		     src="images/thumbs/tile2.jpg"
		     data-image="images/big/tile2.jpg"
		     data-description="Those are peppers"
		     style="display:none">
		</a>

		<a href="http://unitegallery.net">
		<img alt="Keys"
		     src="images/thumbs/tile3.jpg"
		     data-image="images/big/tile3.jpg"
		     data-description="Those are keys"
		     style="display:none">
		</a>

		<a href="http://unitegallery.net">
		<img alt="Friuts in cup"
		     src="images/thumbs/tile4.jpg"
		     data-image="images/big/tile4.jpg"
		     data-description="Those are friuts in a cup"
		     style="display:none">
		</a>

		<a href="http://unitegallery.net">
		<img alt="Yellow Flowers"
		     src="images/thumbs/tile5.jpg"
		     data-image="images/big/tile5.jpg"
		     data-description="Those are yellow flowers"
		     style="display:none">
		</a>

		<a href="http://unitegallery.net">
		<img alt="Butterfly"
		     src="images/thumbs/tile6.jpg"
		     data-image="images/big/tile6.jpg"
		     data-description="This is butterfly"
		     style="display:none">
		</a>

		<a href="http://unitegallery.net">
		<img alt="Boat"
		     src="images/thumbs/tile7.jpg"
		     data-image="images/big/tile7.jpg"
		     data-description="This is a boat"
		     style="display:none">
		</a>

		<a href="http://unitegallery.net">
		<img alt="Woman"
		     src="images/thumbs/tile8.jpg"
		     data-image="images/big/tile8.jpg"
		     data-description="This is a woman"
		     style="display:none">
		</a>

		<a href="http://unitegallery.net">
		<img alt="Cup Of Coffee"
		     src="images/thumbs/tile9.jpg"
		     data-image="images/big/tile9.jpg"
		     data-description="This is cup of coffee"
		     style="display:none">
		</a>

		<a href="http://unitegallery.net">
		<img alt="Iphone Back"
		     src="images/thumbs/tile10.jpg"
		     data-image="images/big/tile10.jpg"
		     data-description="This is iphone back"
		     style="display:none">
		</a>
		<a href="http://unitegallery.net">
		<img alt="Lemon Slice"
		     src="images/thumbs/tile1.jpg"
		     data-image="images/big/tile1.jpg"
		     data-description="This is a Lemon Slice"
		     style="display:none">
		</a>

		<a href="http://unitegallery.net">
		<img alt="Peppers"
		     src="images/thumbs/tile2.jpg"
		     data-image="images/big/tile2.jpg"
		     data-description="Those are peppers"
		     style="display:none">
		</a>

		<a href="http://unitegallery.net">
		<img alt="Keys"
		     src="images/thumbs/tile3.jpg"
		     data-image="images/big/tile3.jpg"
		     data-description="Those are keys"
		     style="display:none">
		</a>

		<a href="http://unitegallery.net">
		<img alt="Friuts in cup"
		     src="images/thumbs/tile4.jpg"
		     data-image="images/big/tile4.jpg"
		     data-description="Those are friuts in a cup"
		     style="display:none">
		</a>

		<a href="http://unitegallery.net">
		<img alt="Yellow Flowers"
		     src="images/thumbs/tile5.jpg"
		     data-image="images/big/tile5.jpg"
		     data-description="Those are yellow flowers"
		     style="display:none">
		</a>

		<a href="http://unitegallery.net">
		<img alt="Butterfly"
		     src="images/thumbs/tile6.jpg"
		     data-image="images/big/tile6.jpg"
		     data-description="This is butterfly"
		     style="display:none">
		</a>

			<a href="http://unitegallery.net">
		<img alt="Cup Of Coffee"
		     src="images/thumbs/tile9.jpg"
		     data-image="images/big/tile9.jpg"
		     data-description="This is cup of coffee"
		     style="display:none">
		</a>

		<a href="http://unitegallery.net">
		<img alt="Iphone Back"
		     src="images/thumbs/tile10.jpg"
		     data-image="images/big/tile10.jpg"
		     data-description="This is iphone back"
		     style="display:none">
		</a>
		<a href="http://unitegallery.net">
		<img alt="Lemon Slice"
		     src="images/thumbs/tile1.jpg"
		     data-image="images/big/tile1.jpg"
		     data-description="This is a Lemon Slice"
		     style="display:none">
		</a>

		<a href="http://unitegallery.net">
		<img alt="Peppers"
		     src="images/thumbs/tile2.jpg"
		     data-image="images/big/tile2.jpg"
		     data-description="Those are peppers"
		     style="display:none">
		</a>


			 
	</div>
	
	<script type="text/javascript">

		jQuery(document).ready(function(){

			jQuery("#gallery").unitegallery({
				tiles_type:"justified"
			});

		});
		
	</script>


</body>
</html>